<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>wareHouseAll</title>
    <script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js"></script>
    <link rel="stylesheet" type="text/css" href="https://cdn.bootcss.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css">
</head>
<body>
    <div style="float: left;margin-left: 180px; margin-top: 20px">
        <div style="float: left;">
            <div style="float: left;">
                <div style="float: left">
                    <table class="table table-striped table-bordered table-hover table-condensed" id='tabletest' style="width: 800px" align="center">
                        <tr style="text-align: center">
                            <th>商品名</th>
                            <th>入库时间</th>
                            <th>描述</th>
                            <th>操作</th>
                            <th><button style="width: 100px;" id="findOutGoods" type="button" onclick="findOutGoods()" class="btn btn-info">出货物品</button></th>
                        </tr>
                    </table>
                </div>

                <div class="row clearfix" style="width: 400px; height: 200px;float: left; margin-left: 50px">
                    <div class="col-md-12 column">
                        <form role="form">
                            <div class="form-group" style="margin-left: 0px">
                                <div>
                                    <label>用户姓名：</label><div id="username" style="display: inline"></div>
                                </div>
                            </div>
                            <div class="form-group" style="margin-left: 0px">
                                <div>
                                    <label>联系电话：</label><div id="tel" style="display: inline"></div>
                                </div>
                            </div>
                            <button id="change" onclick="changeUser()" type="button" class="btn btn-success">切换用户</button>
                            <button type="button" onclick="add()" class="btn btn-info" style="margin-left: 20px">添加商品</button>
                            <button type="button" onclick="allGoods()" class="btn btn-default" style="margin-left: 20px">商品详情</button>
                        </form>
                    </div>
                </div>
            </div>
        </div>

    </div>

</body>
<script>
    document.getElementById("username").innerText = localStorage.getItem("username")
    document.getElementById("tel").innerText = localStorage.getItem("tel")

    $(document).ready(function (t) {
        $.ajax({
            type: 'GET',
            url: "http://49.235.107.34:8081/wh/findExistAll",
            data: {"state": 1},
            success: function (result) {
                for (var i in result.data) {
                    $("table").append(`
                            <tr style="text-align: center">
                                <td>${result.data[i].goodsName}</td>
                                <td>${result.data[i].createTime}</td>
                                <td>${result.data[i].descripe}</td>
                                <td>
                                    <button id="${result.data[i].goodId}"  onclick="outGood(this)" type="button" class="btn btn-success">出库</button>
                                    <button id="${result.data[i].goodId}-${result.data[i].goodsName}-${result.data[i].descripe}" type="button" onclick="updateGood(this)" class="btn btn-primary">修改</button>
                                </td>
                            </tr>
                        `);
                }
            }
        });
    })
        function outGood(t) {
            $.ajax({
                type: 'POST',
                url: "http://49.235.107.34:8081/wh/out",
                data:{"goodId":t.id},
                success: function (result) {
                    if (result.code == 0) {
                        window.location.assign("http://49.235.107.34:8081/wareHouseAll.html")
                    } else {
                        alert("出库失败")
                    }
                }
            });
        }

        function add() {
           window.location.assign("http://49.235.107.34:8081/addGood.html")
        }
        function updateGood(t) {
            localStorage.id = t.id;
            window.location.assign("http://49.235.107.34:8081/updateGood.html")
        }

        function changeUser() {
            window.location.assign("http://49.235.107.34:8081/login.html")
        }
        
        function allGoods() {
            window.location.assign("http://49.235.107.34:8081/goodAll.html")
        }

        function findOutGoods() {
            window.location.assign("http://49.235.107.34:8081/outWHGoods.html")
        }

</script>
</html>